<template>
  <div class="login-page">
    <van-nav-bar
      :title="title"
      left-arrow
      :right-text="rightText"
      fixed
      @click-right="clickRight"
      @click-left="clickLeft"
    />
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'

//定义props
const props = defineProps<{
  title?: string
  rightText?: string
  back?: () => void
}>()

//定义emits

const emit = defineEmits<{
  (e: 'click-right'): void
}>()

//右侧按钮
const clickRight = () => {
  emit('click-right')
}
const router = useRouter()
//左侧箭头
const clickLeft = () => {
  if (props.back) return props.back()
  if (history.state?.back) {
    router.back()
  } else {
    router.push('/')
  }
}
</script>

<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    &__arrow {
      color: var(--cp-text1);
      font-size: 18px;
    }
    &__title {
      font-size: 15px;
    }
  }
}
</style>
